package com.example.monitorapp

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.example.baselib.constants.MyConstants

/**
 * Author: sxygsj
 * Date: 2020/4/20 15:24
 * Description: 主界面按钮adapter
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
class MainBtnAdapter(layoutResId: Int, data: MutableList<BtnData>?) :
    BaseQuickAdapter<BtnData, BaseViewHolder>(layoutResId, data) {
    override fun convert(helper: BaseViewHolder?, item: BtnData?) {
        when (item?.btnId) {
            MyConstants.SAFE -> {
                helper?.setText(R.id.main_item_btn_txt, item.btnName)
                if (item.btnState) {
                    helper?.setBackgroundRes(R.id.main_item_btn_img, R.drawable.btn_safe_0)
                    if (item.btnUpload) {
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_suc)
                    } else
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_err)
                } else
                    helper?.setBackgroundRes(R.id.main_item_btn_img, R.drawable.btn_safe_1)
            }
            MyConstants.PERSON -> {
                helper?.setText(R.id.main_item_btn_txt, item.btnName)
                if (item.btnState) {
                    helper?.setBackgroundRes(R.id.main_item_btn_img, R.drawable.btn_rydw_0)
                    if (item.btnUpload) {
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_suc)
                    } else
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_err)
                } else
                    helper?.setBackgroundRes(R.id.main_item_btn_img, R.drawable.btn_rydw_1)
            }
            MyConstants.VIDEO -> {
                helper?.setText(R.id.main_item_btn_txt, item.btnName)
                if (item.btnState) {
                    helper?.setBackgroundRes(R.id.main_item_btn_img, R.drawable.btn_video_0)
                    if (item.btnUpload) {
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_suc)
                    } else
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_err)
                } else
                    helper?.setBackgroundRes(R.id.main_item_btn_img, R.drawable.btn_video_1)
            }
            MyConstants.PRODUCT -> {
                helper?.setText(R.id.main_item_btn_txt, item.btnName)
                if (item.btnState) {
                    helper?.setBackgroundRes(R.id.main_item_btn_img, R.drawable.btn_yield_0)
                    if (item.btnUpload) {
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_suc)
                    } else
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_err)
                } else
                    helper?.setBackgroundRes(R.id.main_item_btn_img, R.drawable.btn_yield_1)
            }
            MyConstants.DEVICE -> {
                helper?.setText(R.id.main_item_btn_txt, item.btnName)
                if (item.btnState) {
                    helper?.setBackgroundRes(R.id.main_item_btn_img, R.drawable.btn_device_0)
                    if (item.btnUpload) {
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_suc)
                    } else
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_err)
                } else
                    helper?.setBackgroundRes(R.id.main_item_btn_img, R.drawable.btn_device_1)
            }
            MyConstants.RESCUE -> {
                helper?.setText(R.id.main_item_btn_txt, item.btnName)
                if (item.btnState) {
                    helper?.setBackgroundRes(R.id.main_item_btn_img, R.drawable.btn_rescue_0)
                    if (item.btnUpload) {
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_suc)
                    } else
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_err)
                } else
                    helper?.setBackgroundRes(R.id.main_item_btn_img, R.drawable.btn_rescue_1)
            }
            MyConstants.WATER -> {
                helper?.setText(R.id.main_item_btn_txt, item.btnName)
                if (item.btnState) {
                    helper?.setBackgroundRes(R.id.main_item_btn_img, R.drawable.btn_water_0)
                    if (item.btnUpload) {
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_suc)
                    } else
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_err)
                } else
                    helper?.setBackgroundRes(R.id.main_item_btn_img,R.drawable.btn_water_1)
            }
            MyConstants.KZDYL -> {
                helper?.setText(R.id.main_item_btn_txt, item.btnName)
                if (item.btnState) {
                    helper?.setBackgroundRes(R.id.main_item_btn_img, R.drawable.btn_kzdyl_0)
                    if (item.btnUpload) {
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_suc)
                    } else
                        helper?.setBackgroundRes(R.id.main_item_upload_img, R.mipmap.btn_up_err)
                } else
                    helper?.setBackgroundRes(R.id.main_item_btn_img, R.drawable.btn_kzdyl_1)
            }
            else -> {
            }
        }
    }
}